// 高昊宇版本
#include <bits/stdc++.h>
using namespace std;
vector<int> ma[200001];
int mmax = 0;
int location = 0;
void dfs(int deep, int u, int father) {
  for (auto son : ma[u]) {
    if (father != son) {
      dfs(deep + 1, son, u);
    }
  }
  if (deep > mmax) {
    mmax = deep;
    location = u;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int t;
    cin >> t;
    ma[i].push_back(t);
    ma[t].push_back(i);
  }
  dfs(0, 1, 0);
  mmax = 0;
  dfs(0, location, 0);
  cout << mmax;
  return 0;
}